import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import net.mindview.util.TextFile;

public class E20_VowelsInfo {

	private final static Set<Character> vowels = new HashSet<Character>(
			Arrays.asList('a', 'e', 'o', 'u', 'i', 'A', 'E', 'O', 'U', 'I'));

	private static Map<Character, Integer> vowelsInfo = new HashMap<Character, Integer>();

	public static void main(String[] args) {
		HashSet<String> processedWords = new HashSet<String>();
		int fileVowels = 0;
		int wordVowels;
		for (String word : new TextFile("src/E16_Vowels.java", "\\W+")) {
			wordVowels = 0;
			for (char letter : word.toCharArray()) {
				if (vowels.contains(letter)) {
					wordVowels++;
					Integer freq = vowelsInfo.get(letter);
					vowelsInfo.put(letter, freq == null ? 1 : freq + 1);
				}
			}
			if (!processedWords.contains(word)) {
				processedWords.add(word);
				System.out.println(word + " has " + wordVowels + " vowel(s)");
			}
			fileVowels += wordVowels;
		}
		System.out.println("Total number of vowels in file: " + fileVowels);
		System.out.println("vowelsInfo: " + vowelsInfo);
	}
}
